home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / SOURCE / BIN2HDR.CPP < prev    next >
C/C++ Source or Header  |  1992-11-30  |  2KB  |  66 lines

  1. #include <fstream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. void main(int argCount, char ** argVector)
  7. {
  8.   char filename[20], *myCharPointer;
  9.   int myChar;
  10.   int myOtherCounter = 0;
  11.   if (argCount < 2)
  12.   {
  13.     cout << "Yak2Hdr: .yak to header file conversion tool\n\n";
  14.     cout << "USAGE:\nC>yak2hdr <fileSpec>\n";
  15.     cout << "where <fileSpec> is the name of the first file to convert.\n";
  16.     cout << "output goes to file <fileSpec>.h, eliminating extension of <fileSpec>.\n";
  17.     cout << "WARNING: Will overwrite destination file!  Be careful!\n\n";
  18.     exit(0);
  19.   }
  20.   ifstream myInStream;
  21.   ofstream myOutStream;
  22.   for (int counter = 1; counter < argCount; ++counter)
  23.     {
  24.     myInStream.open(argVector[counter]);
  25.     if (myInStream)
  26.     {
  27.       strcpy(filename, argVector[counter]);
  28.       myCharPointer = strchr(filename, '.');
  29.       if (myCharPointer != NULL)
  30.       {
  31.         ++myCharPointer;
  32.         *myCharPointer = 'h';
  33.         ++myCharPointer;
  34.         *myCharPointer = 0;
  35.       }
  36.       myOutStream.open(filename);
  37.       strcpy(filename, argVector[counter]);
  38.       for (myCharPointer = filename; *myCharPointer != 0; ++myCharPointer)
  39.         *myCharPointer = tolower(*myCharPointer);
  40.       myCharPointer = strchr(filename, '.');
  41.       if (myCharPointer != NULL)
  42.       {
  43.         *myCharPointer = toupper(*(myCharPointer + 1));
  44.         ++myCharPointer;
  45.         while(*(myCharPointer) != 0)
  46.         {
  47.           *myCharPointer = *(myCharPointer + 1);
  48.           ++myCharPointer;
  49.         }
  50.       }
  51.       myOutStream << "//header file translated from binary file " << argVector[counter] << "\n\n";
  52.       myOutStream << "unsigned char " << filename << "[] = {\n";
  53.       myOtherCounter = 1;
  54.       while ((myChar = myInStream.get()) != EOF)
  55.       {
  56.         myOutStream << myChar << ", ";
  57.         if (!(myOtherCounter % 10))
  58.           myOutStream << "\n";
  59.         ++myOtherCounter;
  60.       }
  61.       myOutStream << "\n};\n";
  62.       myOutStream.close();
  63.       myInStream.close();
  64.     }
  65.   }
  66. }